package com.lkd.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lkd.entity.SkuClass;
import com.lkd.mapper.SkuClassMapper;
import com.lkd.result.PageBean;
import com.lkd.service.SkuClassService;
import com.lkd.vo.SkuClassVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @className: ShopServiceImpl
 * @description:
 * @author: InnovatorX
 * @date: 2024/5/26 21:22
 * @Version: 1.0
 */
@Service
@Slf4j
public class SkuClassServiceImpl implements SkuClassService {
    @Autowired
    private SkuClassMapper skuClassMapper;

    @Override
    public void saveShop(SkuClass skuClass) {
        skuClassMapper.saveShop(skuClass);
    }

    @Override
    public PageBean<SkuClassVo> search(String className, Integer pageIndex, Integer pageSize) {

        //分页
        PageHelper.startPage(pageIndex, pageSize);

        List<SkuClassVo> skuClassVos = skuClassMapper.selectByPage(className);

        PageBean<SkuClassVo> pageBean = new PageBean<>();
        pageBean.setPageIndex(pageIndex);
        pageBean.setTotalPage((long) ((Page<?>) skuClassVos).getPages());
        pageBean.setPageSize(pageSize);
        pageBean.setTotalCount(((Page<?>) skuClassVos).getTotal());
        pageBean.setCurrentPageRecords(skuClassVos);

        return pageBean;
    }

    @Override
    public SkuClassVo getById(Integer classId) {
        return skuClassMapper.getById(classId);
    }

    @Override
    public void update(SkuClass skuClass) {
        skuClassMapper.update(skuClass);
    }

    @Override
    public void delete(Integer classId) {
        skuClassMapper.delete(classId);
    }
}
